using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace LogikBug
{
	/// <summary>
	/// 
	/// </summary>
	public static class PropertyDescriptorExtensions
	{
		/// <summary>
		/// 
		/// </summary>
		/// <typeparam name="TAttribute"></typeparam>
		/// <param name="propertyDescriptor"></param>
		/// <returns></returns>
		public static TAttribute GetAttribute<TAttribute>(this PropertyDescriptor propertyDescriptor) where TAttribute : Attribute
		{
			propertyDescriptor.ThrowIfNull("propertyDescriptor");
			return propertyDescriptor.Attributes.OfType<TAttribute>().SingleOrDefault();
		}

		/// <summary>
		/// 
		/// </summary>
		/// <typeparam name="TAttribute"></typeparam>
		/// <param name="propertyDescriptor"></param>
		/// <returns></returns>
		public static IEnumerable<TAttribute> GetAttributes<TAttribute>(this PropertyDescriptor propertyDescriptor) where TAttribute : Attribute
		{
			propertyDescriptor.ThrowIfNull("propertyDescriptor");
			return propertyDescriptor.Attributes.OfType<TAttribute>();
		}
	}
}